export default {
  state: {
    totalNum: 0
  },
  mutations: {
    // 初始化totalNum的值
    initTotalNum: (state) => {
      // 读取localStorage中的商品
      let carList = JSON.parse(localStorage.getItem('cartList' || '[]'))
      // 循环数组中的数据，然后将num加起来
      let total = 0
      carList.map(item => {
        total += item.num
      })
      // 赋值
      state.totalNum = total
    },
    // 添加上商品时执行的函数
    addTotalNum: (state) => {
      state.totalNum += 1
    }
  },
  actions: {

  }
}
